const { resolve } = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
// webpack5+ 增加
const EslintWebpackPlugin = require('eslint-webpack-plugin')

module.exports = {
  entry: './src/index.js',
  output: {
    filename: "js/[name].bundle.js",
    path: resolve(__dirname, 'dist')
  },
  module: {
    rules: [
      /*
      * 语法检查：eslint-loader eslint
      * 注意：只检查自己的代码
      * 设置检查规则：
      *   在package.json中 eslintConfig 中设置
      *   "eslintConfig": {
             "extends": "airbnb-base"
          }
      *   airbnb --> eslint-config-airbnb-base eslint-plugin-import eslint
      * */
      {
        test: /\.js$/,
        // loader: 'eslint-loader', // webpack5+ 弃用
        exclude: /node_modules/
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      filename: "./src/template.html"
    }),
    // webpack5+ 增加
    new EslintWebpackPlugin({
      fix: true
    })
  ],
  mode: "development"
}